package com.supplychainapi.param;

import com.google.common.collect.Lists;
import com.supplychainapi.model.ScmTbtreebuild;
import com.supplychainapi.model.Tbdepartment;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.List;

@ApiModel("pc 分类")
public class PcTree {

    @ApiModelProperty("分类名")
    String label;
    @ApiModelProperty("id")
    String value;
    @ApiModelProperty("id")
    String key;
    @ApiModelProperty("级数")
    String level;
    @ApiModelProperty("id")
    String id;
    @ApiModelProperty("父级")
    String pid;
    @ApiModelProperty("级数id 拼接  一级/二级/三级")
    String fullKey;
    @ApiModelProperty("子级")
    List<PcTree> children;

    /**
     *
     * @param tbtreebuilds  分类集合.1->2->3 已经递归好的list
     * @return List<PcTree>
     */
    public static final  List<PcTree> buildTrees(List<ScmTbtreebuild> tbtreebuilds) {
        List<PcTree> trees=Lists.newArrayList();
        tbtreebuilds.stream().forEach(a->{
            PcTree tree=new PcTree();
            tree.setId(a.getFsNodeCode());
            tree.setFullKey(a.getFsNodeFullText());
            tree.setLabel(a.getFsNodeText());
            tree.setPid(a.getFdParentNodeCode());
            tree.setLevel(String.valueOf(a.getFdNodeLevel()));
            tree.setValue(a.getFsNodeCode());
            tree.setKey(a.getFsNodeCode());
            List<ScmTbtreebuild> list= a.getScmTbtreebuildList();
            if(null!=list && !list.isEmpty()){
                List<PcTree> twoTrees= Lists.newArrayList();
                list.stream().forEach(b->{
                    PcTree treeTwo=new PcTree();
                    treeTwo.setId(b.getFsNodeCode());
                    treeTwo.setFullKey(b.getFsNodeFullText());
                    treeTwo.setLabel(b.getFsNodeText());
                    treeTwo.setPid(b.getFdParentNodeCode());
                    treeTwo.setLevel(String.valueOf(b.getFdNodeLevel()));
                    treeTwo.setValue(b.getFsNodeCode());
                    treeTwo.setKey(b.getFsNodeCode());
                    twoTrees.add(treeTwo);
                    if(null!=b.getScmTbtreebuildList()){
                        List<PcTree> threeTrees= Lists.newArrayList();
                        b.getScmTbtreebuildList().stream().forEach(c->{
                            PcTree treeThree=new PcTree();
                            treeThree.setId(c.getFsNodeCode());
                            treeThree.setFullKey(c.getFsNodeFullText());
                            treeThree.setLabel(c.getFsNodeText());
                            treeThree.setPid(c.getFdParentNodeCode());
                            treeThree.setLevel(String.valueOf(c.getFdNodeLevel()));
                            treeThree.setValue(c.getFsNodeCode());
                            treeThree.setKey(c.getFsNodeCode());
                            threeTrees.add(treeThree);
                        });
                        treeTwo.setChildren(threeTrees);
                    }
                });
                tree.setChildren(twoTrees);
            }
            trees.add(tree);
        });
        return trees;
    }
    
    public static final List<PcTree> deptTrees(List<Tbdepartment> depts){
    	List<PcTree> trees=Lists.newArrayList();
    	depts.stream().forEach(a->{
            PcTree tree=new PcTree();
            tree.setId(a.getFsDepartmentId());
            tree.setFullKey(a.getFsDepartmentName());
            tree.setLabel(a.getFsDepartmentName());
            tree.setPid("0");
            tree.setLevel("1");
            tree.setValue(a.getFsDepartmentId());
            tree.setKey(a.getFsDepartmentId());
            trees.add(tree);
    	});
    	return trees;
    }

    public PcTree() {
    }

    public PcTree(String label, String value, String key, String level, String id, String pid, String fullKey, List<PcTree> children) {
        this.label = label;
        this.value = value;
        this.key = key;
        this.level = level;
        this.id = id;
        this.pid = pid;
        this.fullKey = fullKey;
        this.children = children;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public String getFullKey() {
        return fullKey;
    }

    public void setFullKey(String fullKey) {
        this.fullKey = fullKey;
    }

    public List<PcTree> getChildren() {
        return children;
    }

    public void setChildren(List<PcTree> children) {
        this.children = children;
    }
}
